<!-------------------------------------
ページ名：SupplementaryClasses.jsp
所　　属：H3A1 04
名　　前：大瀬碩
説　　明：振り替え補講申請ページ
--------------------------------------->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.sql.*"%>
<%@page import="java.util.Properties"%>
    <%@page import="java.util.*"%>
    <%@page import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script>
$(function() {
    $('#tablefix').tablefix({width: 500, height: 200, fixRows: 2, fixCols: 2});
});
</script>

<title>振り替え補講申請</title>
</head>
<body>
<!-- ナビゲーションバー -->
<div class="navbar navbar-default">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="index.jsp"><img alt="" src="images/logo2.png"></a>
  </div>
  <div class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
      <li><a href="TimetableClassSelection.jsp">時間割情報</a></li>
      <li><a href="ClubList.jsp">部活動情報</a></li>
      <li class="active"><a href="SupplementaryClasses.jsp">振り替え補講</a></li>
      <li><a href="HolidayAttendance.jsp">土日出校申請</a></li>
      <li><a href="AttendanceHistory.jsp">出席履歴</a></li>
    </ul>
    <ul class="nav navbar-nav navbar-right">
      <li><a href="<%out.print(request.getContextPath());%>/Logout">ログアウト</a></li>
    </ul>
  </div>
</div>
<h1 align="center">振り替え補講履歴</h1>
<div class="container">
	<div align="center">
		<table class="table table-bordered table-striped" id="tablefix">
			<tr class="success">
				<th>
					補講実施日
				</th>
				<th>
					補講開始時刻
				</th>
				<th>
					補講終了時刻
				</th>
				<th>
					補講内容
				</th>
			<tr>
			<%
			//DBから補講履歴を取得
			HttpSession ses = request.getSession(true);
			try{
				ServletContext context = this.getServletContext();
				String path = context.getRealPath("/WEB-INF/connect.properties");
				
				InputStream in = new FileInputStream(path);
				Properties properties = new Properties();
				properties.load(in);
				in.close();
				
				
		    	
		    	Object id = ses.getAttribute("id");
				
				Class.forName("com.mysql.jdbc.Driver");
				Connection conn = null;
				String url = properties.getProperty("key1");
				String user = properties.getProperty("key2");
				String password = properties.getProperty("key3");
				conn = DriverManager.getConnection(url, user, password);
				Statement stmt = conn.createStatement();
				String sql = "SELECT * FROM makeup_class WHERE student_id = "+id+
						" AND acceptance_flag != 0";
				ResultSet rs = stmt.executeQuery(sql);
				while(rs.next()){
					out.print("<tr>");
					out.print("<td>");
					out.print(rs.getString("date_and_supplementary"));
					out.print("</td>");
					out.print("<td>");
					out.print(rs.getString("start_time"));
					out.print("</td>");
					out.print("<td>");
					out.print(rs.getString("end_time"));
					out.print("</td>");
					out.print("<td>");
					out.print(rs.getString("content"));
					out.print("</td>");
				}
				rs.close();
				stmt.close();
				conn.close();
			}
			catch (ClassNotFoundException e){
				
			}
			catch (SQLException e){
				
			}
			catch (Exception e){
				
			}
			%>
		</table>
	</div>
</div>

<h1 align="center">振り替え補講申請</h1>
	<table align="center">
		<tr>
			<td></td>
			<td>
				<form name="SCS" method="post" action="Start">
					<%
					//補講開始ボタンの動作
					Object stbtn = ses.getAttribute("stbtn");
					if("ON".equals(stbtn)){
						out.println("<input type=\"submit\" value=\"補講開始\" class=\"btn btn-lg btn-warning\" name=\"st\" disabled>");
						
						Object st = ses.getAttribute("st");
						
					    out.println("<font size=\"4\">"+st+"</font>");
					}else{
						
						Calendar cal1 = Calendar.getInstance();
					    int month = cal1.get(Calendar.MONTH) + 1;
					    int day = cal1.get(Calendar.DATE);
					    int hour = cal1.get(Calendar.HOUR_OF_DAY);
					    int minute = cal1.get(Calendar.MINUTE);
					    int second = cal1.get(Calendar.SECOND);
					    
					    String st = month+"/"+day+" "+hour+":"+minute;
					    
					    out.println("<input type=\"hidden\" value=\""+st+"\" name=\"st\">");
					    
					    out.println("<input type=\"hidden\" value=\""+hour+":"+minute+":"+second+"\" name=\"str\">");
					    
					    out.println("<input type=\"submit\" value=\"補講開始\" class=\"btn btn-lg btn-warning\" name=\"st\">");
					    
					    out.println("<font size=\"4\">"+st+"</font>");
					}
					%>
				</form>
			</td>
		</tr>
		
		<tr><td>　</td></tr>
		
		
		<tr>
			<td></td>
			<td>
				<form name="SCS" method="post" action="End">
					<%
					//補講終了ボタンの動作
					Object etbtn = ses.getAttribute("etbtn");
					if("OFF".equals(etbtn)){
						Calendar cal1 = Calendar.getInstance();
					    int month = cal1.get(Calendar.MONTH) + 1;
					    int day = cal1.get(Calendar.DATE);
					    int hour = cal1.get(Calendar.HOUR_OF_DAY);
					    int minute = cal1.get(Calendar.MINUTE);
					    int second = cal1.get(Calendar.SECOND);
					    
					    String et = month+"/"+day+" "+hour+":"+minute;
					    
					    out.println("<input type=\"hidden\" value=\""+et+"\" name=\"et\">");
					    
					    out.println("<input type=\"hidden\" value=\""+hour+":"+minute+":"+second+"\" name=\"etr\">");
					    
					    out.println("<input type=\"submit\" value=\"補講終了\" class=\"btn btn-lg btn-warning\" name=\"et\">");
					    
					    out.println("<font size=\"4\">"+et+"</font>");
					}
					else if("ON".equals(etbtn)){
						out.println("<input type=\"submit\" value=\"補講終了\" class=\"btn btn-lg btn-warning\" name=\"et\" disabled>");
						Object et = ses.getAttribute("et");
						
					    out.println("<font size=\"4\">"+et+"</font>");
					}else{
						out.println("<input type=\"submit\" value=\"補講終了\" class=\"btn btn-lg btn-warning\" name=\"et\" disabled>");
						Calendar cal1 = Calendar.getInstance();
					    int month = cal1.get(Calendar.MONTH) + 1;
					    int day = cal1.get(Calendar.DATE);
					    int hour = cal1.get(Calendar.HOUR_OF_DAY);
					    int minute = cal1.get(Calendar.MINUTE);
					    int second = cal1.get(Calendar.SECOND);
					    
					    String et = month+"/"+day+" "+hour+":"+minute;
					    out.println("<font size=\"4\">"+et+"</font>");
					}
					%>
				</form>
			</td>
		</tr>
		
		<tr><td>　</td></tr>
		
		<tr><td></td><td>補講開始・終了ボタンを押してから入力してください。</td></tr>
		
		<form name="SCS" method="post" action="SupplementaryClasses">
		
		<tr>
			<td>補講内容</td>
			<td><%
			Object actedit = ses.getAttribute("actedit");
			if("OFF".equals(actedit)){
				out.println("<textarea name=\"scact\" cols=\"27\" rows=\"10\" class=\"form-control\"></textarea>");
			}else{
				out.println("<textarea name=\"scact\" cols=\"27\" rows=\"10\" class=\"form-control\" disabled></textarea>");
			}
			
			%>
			</td>
		</tr>
		
		<tr><td>　</td></tr>
		
		<tr>
			<td></td>
			<td align="center">
			<a href="index.jsp" class="btn btn-lg btn-danger"><i class="glyphicon glyphicon-arrow-left"><br>戻る</i></a>
			<button class="btn btn-lg btn-danger" type="submit"><i class="glyphicon glyphicon-upload"><br>送信</i></button>
			</td>
		</tr>
		</form>
	</table>
</body>
</html>